<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta property="og:type" content="website">
<meta property="og:title" content="Hexo">
<meta property="og:url" content="http://example.com/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main">
  
    <article id="post-wode-one" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2021/05/15/wode-one/" class="article-date">
  <time class="dt-published" datetime="2021-05-14T18:41:03.352Z" itemprop="datePublished">2021-05-15</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <hr>
<p>title: rabbitmq（一）-基础入门<br>date: 2021-05-15 02:40:19<br>tags:<br>–</p>
<h1 id="在学东西之前，我们先有一个方法论，知道如何学习。学习一个东西一般都遵循以下几个环节："><a href="#在学东西之前，我们先有一个方法论，知道如何学习。学习一个东西一般都遵循以下几个环节：" class="headerlink" title="在学东西之前，我们先有一个方法论，知道如何学习。学习一个东西一般都遵循以下几个环节："></a>在学东西之前，我们先有一个方法论，知道如何学习。学习一个东西一般都遵循以下几个环节：</h1><ol>
<li>xxx是什么，诞生的原因，能解决什么问题。</li>
<li>如何安装，如何使用（快起启动一个demo）。</li>
<li>涉及到的一些基础概念介绍和基础入门使用。</li>
<li>中阶、高阶的功能特性使用。</li>
<li>高可用部署方案。</li>
<li>原理的深入理解。</li>
</ol>
<h3 id="这篇文章主要处于第一、二环节，让新手更好得入门。"><a href="#这篇文章主要处于第一、二环节，让新手更好得入门。" class="headerlink" title="这篇文章主要处于第一、二环节，让新手更好得入门。"></a>这篇文章主要处于第一、二环节，让新手更好得入门。</h3><h2 id="1、rabbitmq是什么"><a href="#1、rabbitmq是什么" class="headerlink" title="1、rabbitmq是什么"></a>1、rabbitmq是什么</h2><p>rabbitmq 是目前非常热门的一款消息中间件。Rabbit 这样名字，是因为兔子行动非常迅速且繁殖起来非常疯狂， RabbitMQ 的开创者认为以此命名这个分布式软件再合适不过了。</p>
<p>RabbitMQ 是采用 Erlang 语言实现 AMQP (Advanced Message Queuing Protocol，高级消息队列协议）的消息中间件，它最初起源于<strong>金融系统</strong>，所以rabbitmq的特点是<em>可靠性传输，性能在可靠性后面</em></p>
<h1 id="2、为什么要使用mq，为什么要选rabbitmq"><a href="#2、为什么要使用mq，为什么要选rabbitmq" class="headerlink" title="2、为什么要使用mq，为什么要选rabbitmq"></a>2、为什么要使用mq，为什么要选rabbitmq</h1><h3 id="为什么要使用mq？"><a href="#为什么要使用mq？" class="headerlink" title="为什么要使用mq？"></a>为什么要使用mq？</h3><p>mq一般有两种模式<br>一种是点对点模式：主要是为了削峰和异步。<br>另一种是广播模式：主要是为了业务之间的解耦。</p>
<p>简单说就是业务有需要对流量削峰的场景，有需要对业务解耦场景。</p>
<h3 id="为什么要选rabbitmq？"><a href="#为什么要选rabbitmq？" class="headerlink" title="为什么要选rabbitmq？"></a>为什么要选rabbitmq？</h3><p>rabbitmq的特点如下：<br>1、<strong>可靠性</strong>： RabbitMQ是为了金融系统而生， 所以特地使用一些机制来保证可靠性，如持久化、传输确认及发布确认等。<br>2、灵活的路由器：4种路由器<br>3、<strong>扩展性</strong>：多个 rabbitmq 节点可以组成个集群，也可以根据实际业务情况动态地扩展集群中节点。<br>4、高可用：拥有镜像队列防止容灾消息丢失。</p>
<p>让我们使用mq产品做重要的业务处理（例如金额、订单）的时候，我们最基本的述求是<br>1、可靠稳定，消息不丢失。<br>2、有集群容灾方案。<br>3、灵活的功能特性。<br>4、性能在可靠的基础上<br>rabbitmq都能完美胜任。</p>
<h2 id="4、rabbitmq的安装"><a href="#4、rabbitmq的安装" class="headerlink" title="4、rabbitmq的安装"></a>4、rabbitmq的安装</h2><p>这里只介绍docker安装方式<br><code>docker run -d --hostname rabbit1 --net=host --name myrabbit1  rabbitmq:3.6.15-management</code></p>
<p>安装之后访问 <code>localhost:15672</code>（localhost改服务器ip）见到如下界面代表安装成功。<br><img src="https://upload-images.jianshu.io/upload_images/22777058-1b53fba0eaec34a4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"><br>使用默认账号guest/guest登录</p>
<p><img src="https://upload-images.jianshu.io/upload_images/22777058-5ab5f6691b825984.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"></p>
<p>管理台的界面后续再一个一个地方详细讲解。</p>
<p>4、快速使用的demo<br>这里以springboot为例子展示如何快速使用rabbitmq<br>4.1 新建springboot工程同时增加配置</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">spring.rabbitmq.host=localhost</span><br><span class="line">spring.rabbitmq.username=guest</span><br><span class="line">spring.rabbitmq.password=guest</span><br></pre></td></tr></table></figure>

<p>4.2 引入ampq的springboot-start依赖</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-boot-starter-amqp&lt;/artifactId&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
<p>4.3 新建配置文件，初始化队列</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">public class RabbitMqConfig &#123;</span><br><span class="line">    @Bean</span><br><span class="line">    public Queue demo()&#123;</span><br><span class="line">        Queue demo = new Queue(&quot;demo&quot;);</span><br><span class="line">        return demo;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>4.4 新建消费者、生产者。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">@RestController</span><br><span class="line">@RequestMapping</span><br><span class="line">public class Controller &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    private RabbitTemplate rabbitTemplate;</span><br><span class="line">    @GetMapping(&quot;sendMq&quot;)</span><br><span class="line">    public String sendMq(String msg)&#123;</span><br><span class="line">        rabbitTemplate.convertAndSend(&quot;demo&quot;,msg);</span><br><span class="line">        return msg;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">@Component</span><br><span class="line">public class DemoLister &#123;</span><br><span class="line">    @RabbitListener(queues = &quot;demo&quot;)</span><br><span class="line">    public void Lister(Message message)&#123;</span><br><span class="line">        byte[] body = message.getBody();</span><br><span class="line">        System.out.println(&quot;接受到的消息体：&quot;+new String(body));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>4.5 发送消息查看效果<br>执行命令<code>curl localhost:8080/sendMq?msg=abc</code><br>查看效果<br><img src="https://upload-images.jianshu.io/upload_images/22777058-1e304d4ea1c62d4c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"></p>
<p>5、最后<br><code>git clone -b teacher-1 https://gitee.com/guoeryyj/rabbitmq-teacher.git</code>下载试例代码</p>
<p>$\color{red}{欢迎关注我的微信公众号：进阶者euj}$</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2021/05/15/wode-one/" data-id="ckor50r0l00010gmeepwn0wkd" data-title="" class="article-share-link">Share</a>
      
      
      
    </footer>
  </div>
  
</article>



  
    <article id="post-hello-world" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2021/05/15/hello-world/" class="article-date">
  <time class="dt-published" datetime="2021-05-14T18:30:28.818Z" itemprop="datePublished">2021-05-15</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/2021/05/15/hello-world/">Hello World</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <p>Welcome to <a target="_blank" rel="noopener" href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a target="_blank" rel="noopener" href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a target="_blank" rel="noopener" href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a target="_blank" rel="noopener" href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">&quot;My New Post&quot;</span></span><br></pre></td></tr></table></figure>

<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/writing.html">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>

<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/server.html">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>

<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/generating.html">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>

<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2021/05/15/hello-world/" data-id="ckor50r0e00000gme649765r6" data-title="Hello World" class="article-share-link">Share</a>
      
      
      
    </footer>
  </div>
  
</article>



  


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/05/">May 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2021/05/15/wode-one/">(no title)</a>
          </li>
        
          <li>
            <a href="/2021/05/15/hello-world/">Hello World</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.4.1.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>